package com.zjuh.goodboy.items;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public class ItemUtil {
	
	public static Map<String, String> itemToMap(Item item) {
		if (item == null) {
			return null;
		}
		Map<String, String> ret = new HashMap<String, String>();
		ret.put("id", String.valueOf(item.getId()));
		ret.put("description", item.getDescription());
		ret.put("imgUrl", item.getImgUrl());
		ret.put("name", item.getName());
		ret.put("siteName", item.getSiteName());
		ret.put("url", item.getUrl());
		return ret;
	}
	
	public static Item rsToItem(ResultSet rs) throws SQLException {
		Item item = new Item();
		item.setId(rs.getLong("id"));
		item.setDescription(rs.getString("description"));
		item.setImgUrl(rs.getString("img_url"));
		item.setName(rs.getString("name"));
		item.setSiteName(rs.getString("site_name"));
		item.setUrl(rs.getString("url"));
		return item;
	}

}
